package com.imooc.controller;

import com.google.gson.Gson;
import com.imooc.Interceptor.JwtCurrentUserInterceptor;
import com.imooc.base.BaseInfoProperties;
import com.imooc.pojo.Users;
import com.imooc.service.UsersService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.servlet.http.HttpServletRequest;

/**
 * @author liansen
 * @create 12-14-23:08
 */
@RestController
@RequestMapping("u")
public class UserController extends BaseInfoProperties {

    @Autowired
    private UsersService usersService;

    @Value("${server.port}")
    private String port;

    @RequestMapping("/test")
    public Object test(){
        System.out.println("jrebel生效了");
        return "hello userService: " + port;
    }


    @RequestMapping("/test2")
    public Object test2(HttpServletRequest request){
        String userJson = request.getHeader(APP_USER_JSON);
        Users user = new Gson().fromJson(userJson, Users.class);
        System.out.println("user:" + user.toString());
        return "111";
    }

    /*
        通过ThreadLocal获取用户信息
     */
    @GetMapping("/test3")
    public Object test3(){
        Users users = JwtCurrentUserInterceptor.currentUser.get();
        String user = new Gson().toJson(users);
        System.out.println("用户信息:" + user);
        return 222;
    }
}
